<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/23
 * Time: 17:32
 */

if (!function_exists('T')) {
    /**
     * Translate the given message.
     *
     * @param  string $key
     * @param  array $replace
     * @param  string $locale
     * @return \Illuminate\Contracts\Translation\Translator|string|array|null
     */
    function T($key = null, $locale = null)
    {
        if(empty($locale)){
            $locale = request()->cookie('multi_lang','en');
            $locale = str_replace(['en','zh_cn','fr'],['en','zh-CN','fr'],$locale);
        }

        return trans('common.' . $key, [], $locale);
    }

}

if (!function_exists('path')) {
    /**
     * Translate the given message.
     *
     * @param  string $key
     * @param  array $replace
     * @param  string $locale
     * @return \Illuminate\Contracts\Translation\Translator|string|array|null
     */
    function path($path)
    {
        return asset($path);
    }

}
if (!function_exists('isBase64encode')) {
    function isBase64encode($val)
    {
        $base64_val = base64_decode($val);
        return base64_encode($base64_val) ? $base64_val : $val;
    }
}
if (!function_exists('unescape')) {
    function unescape($str) {
        $str = rawurldecode($str);
        preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r);
        $ar = $r[0];
        foreach($ar as $k=>$v) {
            if(substr($v,0,2) == "%u")
                $ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4)));
            elseif(substr($v,0,3) == "&#x")
                $ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,3,-1)));
            elseif(substr($v,0,2) == "&#") {
                $ar[$k] = iconv("UCS-2","GBK",pack("n",substr($v,2,-1)));
            }
        }
        return join("",$ar);
    }
}